package com.atguigu.common.feign;

import com.atguigu.spzx.utils.DYLAssert;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

public class UserTokenInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        DYLAssert.notNull(requestAttributes,"requestAttributes为空");
        HttpServletRequest request = requestAttributes.getRequest();
        String header = request.getHeader("userJson");
        requestTemplate.header("userJson", header);
    }
}
